package io.mvvm.filter;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

/**
 * @program: spring-cloud-alibaba
 * @description: 过滤消息提供者
 * @author: 潘
 * @create: 2020-12-27 22:53
 **/
public class Producer {

    public static void main(String[] args) throws Exception{
        // 实例化一个生产者来产生延时消息
        DefaultMQProducer producer = new DefaultMQProducer("group1");
        // 启动生产者
        producer.start();
        int totalMessagesToSend = 100;
        for (int i = 0; i < totalMessagesToSend; i++) {
            Message message = new Message("FilterTopic", ("Hello Filter message " + i).getBytes());
            // 设置一些属性
            message.putUserProperty("key", String.valueOf(i));
            // 发送消息
            SendResult send = producer.send(message);
            System.out.println(send);
        }
        // 关闭生产者
        producer.shutdown();
    }
}
